package LeetCode.month02.day35;

import java.util.Arrays;
import java.util.Map;

public class No135 {
    public static void main(String[] args) {
        System.out.println(candy(new int[]{1,2,87,87,87,2,1}));
    }
    public static int candy(int[] ratings) {
        int n = ratings.length;
        int[] res = new int[n];
        int sum = n;
        for (int i = 1; i < n; i++) {
            if(ratings[i]>ratings[i-1]) res[i] = res[i-1]+1;
        }
        for (int i = ratings.length - 2; i >= 0; i--) {
            if(ratings[i]>ratings[i+1]) res[i] = Math.max(res[i],res[i+1]+1);
            sum+=res[i];
        }
        sum+=res[n-1];
        return sum;
    }
}
